//
//  QuitView.m
//  LubanWork
//
//  Created by xiaohao on 2020/1/7.
//  Copyright © 2020 xiaohao. All rights reserved.
//

#import "QuitView.h"

@implementation QuitView



-(instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = kColorFromARGBHex(0x000000, 0.5);
        UIView *view = [[UIView alloc] init];
        
        self.frame = [UIScreen mainScreen].bounds;
        
        [self addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_offset(kSCRATIO(275));
            make.height.mas_offset(kSCRATIO(250));
        }];
        view.backgroundColor = kColorFromRGBHex(0xFFFFFF);
        
        
        ViewRadius(view, KSCHEIGHT(10));
        
        UIImageView *imageView = [[UIImageView alloc] init];
        [view addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view).offset(kSCRATIO(25));
            make.left.equalTo(view).offset(kSCRATIO(85.5));
            make.right.equalTo(view).offset(-kSCRATIO(85.5));
            make.height.mas_offset(kSCRATIO(53));
        }];
        
        imageView.image = [UIImage imageNamed:@"success"];
        
        UILabel *success = [UILabel CreatLabeltext:@"报名成功" Font:kFONT(17) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentCenter];
        
        [view addSubview:success];
        
        [success mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view.mas_centerX);
            make.top.equalTo(imageView.mas_bottom).offset(kSCRATIO(18));
            make.width.equalTo(view);
            make.height.mas_offset(kSCRATIO(18));
        }];
        
        
        UIView *weChatView = [[UIView alloc] init];
        
        [view addSubview:weChatView];
        
        [weChatView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view.mas_centerX);
            make.top.equalTo(success.mas_bottom).offset(kSCRATIO(33));
            make.height.mas_offset(kSCRATIO(31.5));
            make.width.mas_offset(kSCRATIO(226.5));
        }];
        
        weChatView.layer.borderWidth = kSCRATIO(1.5);
        weChatView.layer.borderColor = kColorFromRGBHex(0x4CB202).CGColor;
        ViewRadius(weChatView, KSCHEIGHT(5));
        
        UIImageView *weChatImage = [[UIImageView alloc] init];
        
        weChatImage.image = [UIImage imageNamed:@"WeChat"];
        
        [weChatView addSubview:weChatImage];
        
        [weChatImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weChatView.mas_centerY);
            make.left.equalTo(weChatView).offset(kSCRATIO(64));
            make.width.height.mas_offset(kSCRATIO(20));
        }];
        
        UILabel *weChatLab = [UILabel CreatLabeltext:@"8888888" Font:kFONT(15) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentLeft];
        
        [weChatView addSubview:weChatLab];
        
        [weChatLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weChatView.mas_centerY);
            make.left.equalTo(weChatImage.mas_right).offset(kSCRATIO(8.5));
            make.height.mas_offset(kSCRATIO(13));
            make.right.equalTo(weChatView.mas_right);
        }];
        
        UIButton *openInWeChat = [UIButton CreatButtontext:@"复制并在微信打开" image:nil Font:kFONT(16) Textcolor:kColorFromRGBHex(0xFFFFFF)];
        
        [view addSubview:openInWeChat];
        openInWeChat.backgroundColor = kColorFromRGBHex(0x4CB202);
        ViewRadius(openInWeChat, KSCHEIGHT(18.5));
        
        [openInWeChat mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset(kSCRATIO(145));
            make.height.mas_offset(kSCRATIO(37));
            make.centerX.equalTo(view.mas_centerX);
            make.bottom.equalTo(view.mas_bottom).offset(-kSCRATIO(15));
        }];
        
        ViewRadius(openInWeChat, KSCHEIGHT(18.5));
        
        
        [openInWeChat addTarget:self action:@selector(openWechat:) forControlEvents:UIControlEventTouchUpInside];
        
        
        
        UIButton  *closeImage  = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:closeImage];
        
        [closeImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.width.height.mas_offset(kSCRATIO(30));
            make.top.equalTo(view.mas_bottom).offset(kSCRATIO(30));
        }];
        
        [closeImage setImage:[UIImage imageNamed:@"cancelBtn"] forState:UIControlStateNormal];
        
        [closeImage addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

-(instancetype)initWithType:(BOOL)isGoto{
    self = [super init];
    if (self) {
        self.backgroundColor = kColorFromARGBHex(0x000000, 0.5);
        UIView *view = [[UIView alloc] init];
        
        self.frame = [UIScreen mainScreen].bounds;
        
        [self addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_offset(kSCRATIO(275));
            make.height.mas_offset(kSCRATIO(166));
        }];
        view.backgroundColor = kColorFromRGBHex(0xFFFFFF);
        
        
        ViewRadius(view, KSCHEIGHT(10));
        
        
//        UILabel *title = [UILabel CreatLabeltext:@"提示" Font:kFONT(15) Textcolor:kColorFromRGBHex(0x775FFB) textAlignment:NSTextAlignmentCenter];
        UILabel *title = [UILabel CreatLabeltext:@"提示" Font:kFONT(15) Textcolor:[UIColor colorWithRed:248/255.0 green:80/255.0 blue:92/255.0 alpha:1.0] textAlignment:NSTextAlignmentCenter];
        [view addSubview:title];
        
        [title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view).offset(kSCRATIO(16));
            make.centerX.equalTo(view.mas_centerX);
            make.height.mas_offset(kSCRATIO(14.5));
            make.width.mas_offset(kSCRATIO(40));
        }];
        
        UILabel *messgae = [UILabel CreatLabeltext:@"确定要退出登录吗？" Font:kFONT(15) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentCenter];
        
        [view addSubview:messgae];
        
        [messgae mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view.mas_centerX);
            make.top.equalTo(title.mas_bottom).offset(kSCRATIO(32.5));
            make.height.mas_offset(kSCRATIO(15));
            make.width.equalTo(view);
        }];
        
        
        UIButton *gotoLoginBtn = [UIButton CreatButtontext:@"确定" image:nil Font:kFONT(16) Textcolor:ColorWhite];
        [view addSubview:gotoLoginBtn];
        [gotoLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view.mas_centerX);
            make.top.equalTo(messgae.mas_bottom).offset(kSCRATIO(36.5));
            make.width.mas_offset(kSCRATIO(145));
            make.height.mas_offset(kSCRATIO(37));
        }];
        
        ViewRadius(gotoLoginBtn, KSCHEIGHT(18.5));
//        gotoLoginBtn.backgroundColor = kColorFromRGBHex(0x775FFB);
        gotoLoginBtn.backgroundColor =  [UIColor colorWithRed:248/255.0 green:80/255.0 blue:92/255.0 alpha:1.0];
        
        [gotoLoginBtn addTarget:self action:@selector(openWechat:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton  *closeImage  = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:closeImage];
        
        [closeImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.width.height.mas_offset(kSCRATIO(30));
            make.top.equalTo(view.mas_bottom).offset(kSCRATIO(30));
        }];
        
        [closeImage setImage:[UIImage imageNamed:@"cancelBtn"] forState:UIControlStateNormal];
        
        [closeImage addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}


-(void)show{
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
}

-(void)dismiss{
    [self removeAllSubviews];
    [self removeFromSuperview];
}

-(void)openWechat:(UIButton *)sender{
    [UserModel clearData:UserKey0];
    
    [[AppDelegate shareAppDelegate] setLoginViewController];
    
    [self dismiss];
}



+(void)gotoLoginViewController{
    QuitView *gotinto = [[QuitView alloc] initWithType:YES];
    
    [gotinto show];
}

@end
